import wp from './utils/wp'
import testUtil from './utils/testUtil'
class Test {

    canIUseTest () {
        testUtil('canIUse test', wp
            .canIUse('openBluetoothAdapter'))
            .should(true)
    }

    getSystemInfoSyncTest () {
        testUtil('getSystemInfoSyncTest test',
            wp.getSystemInfoSync()
            .hasOwnProperty('windowHeight'))
            .should(true)
    }

    getSystemInfoTest () {
        wp.getSystemInfo().success(res => {
            testUtil('getSystemInfoTest-success test').success()
        }).complete(res => {
            testUtil('getSystemInfoTest-complete test').success()
        }).fail(err => {
            console.error('获取信息出错')
            console.error(err)
        })
    }

    getLaunchOptionsSyncTest () {
        testUtil('getLaunchOptionsSyncTest test', wp
            .getLaunchOptionsSync()
            .hasOwnProperty('path'))
            .should(true) 
    }

    switchTabTest () {
        wp.switchTab('/pages/index/index')
        .success(res => {
            testUtil('switchTabTest-success test').success()
        }).complete(res => {
            testUtil('switchTabTest-complete test').success()
        }).fail(err => {
            testUtil('switchTabTest-fail test').success()
        })
    }

    reLaunchTest () {
        wp.reLaunch('/pages/index/index')
        .success(res => {
            testUtil('reLaunchTest-success test').success()
        }).complete(res => {
            testUtil('reLaunchTest-complete test').success()
        }).fail(err => {
            testUtil('reLaunchTest-fail test').success()
        })
    }

    redirectToTest () {
        wp.redirectTo('/pages/index/index')
        .success(res => {
            testUtil('redirectToTest-success test').success()
        }).complete(res => {
            testUtil('redirectToTest-complete test').success()
        }).fail(err => {
            testUtil('redirectToTest-fail test').success()
        })
    }

    navigateToTest () {
        wp.navigateTo('/pages/index/index')
        .success(res => {
            testUtil('navigateToTest-success test').success()
        }).complete(res => {
            testUtil('navigateToTest-complete test').success()
        }).fail(err => {
            testUtil('navigateToTest-fail test').success()
        })
    }

    navigateBackTest () {
        wp.navigateTo('/pages/test/test').success(() => {
            setTimeout(() => {
                wp.navigateBack(1)
                    .success(res => {
                        testUtil('navigateBackTest-success test').success()
                    }).complete(res => {
                        testUtil('navigateBackTest-complete test').success()
                    }).fail(err => {
                        testUtil('navigateBackTest-fail test').success()
                    })
            }, 2000)
            
        })
    }

    showToastTest () {
        wp.showToast({
            title: '提示内容'
        }).success(() => {
            testUtil('showToastTest-success test').success()
        }).complete(() => {
            testUtil('showToastTest-complete test').success()
        })
    }

    showModalTest () {
        wp.showModal({
            title: '标题',
            content: '提示内容',
        }).success((res) => {
            testUtil('showModal-success test', res.confirm || res.cancel).should(true)
        }).complete(() => {
            testUtil('showModal-complete test').success()
        })
    }

    showLoadingTest () {
        wp.showLoading({
            title: '加载中...',
            mask: true
        }).success((res) => {
            testUtil('showLoading-complete test').success()
        }).complete(() => {
            testUtil('showLoading-complete test').success()
        })
    }

    showActionSheetTest () {
        wp.showActionSheet({
            itemList: ['A', 'B', 'C']
        }).success((res) => {
            testUtil('showActionSheet-complete test').success()
        }).complete(() => {
            testUtil('showActionSheet-complete test').success()
        })
    }

    hideToastTest () {
        wp.showToast({
            title: '操作成功！',
            duration: 2000
        })
        setTimeout(() => {
            wp.hideToast().success(() => {
                testUtil('hideToastTest-success test').success()
            }).fail(() => {
                testUtil('hideToastTest-fail test').success()
            }).complete(() => {
                testUtil('hideToastTest-complete test').success()
            })
        }, 1000)
    }

    hideLoadingTest () {
        wp.showLoading({
            title: '加载中...'
        })
        setTimeout(() => {
            wp.hideLoading().success(() => {
                testUtil('hideLoadingTest-success test').success()
            }).fail(() => {
                testUtil('hideLoadingTest-fail test').success()
            }).complete(() => {
                testUtil('hideLoadingTest-complete test').success()
            })
        }, 1000)
    }

    showNavigationBarLoadingTest () {
        wp.showNavigationBarLoading({
            itemList: ['A', 'B', 'C']
        }).success((res) => {
            testUtil('showNavigationBarLoading-complete test').success()
        }).complete(() => {
            testUtil('showNavigationBarLoading-complete test').success()
            setTimeout(() => {
                wp.hideNavigationBarLoading()
                    .success(() => {
                        testUtil('hideNavigationBarLoading-complete test').success()
                    })
                    .fail(() => {
                        testUtil('hideNavigationBarLoading-complete test').success()
                    })
                    .complete(() => {
                        testUtil('hideNavigationBarLoading-complete test').success()
                    })
            }, 2000)
        })
    }

    setNavigationBarTitleTest () {
        wp.setNavigationBarTitle({
            title: '测试'
        }).success(() => {
            testUtil('setNavigationBarTitle-success test').success()
        }).fail(() => {
            testUtil('setNavigationBarTitle-fail test').success()
        }).complete(() => {
            testUtil('setNavigationBarTitle-complete test').success()
        })
    }

    setNavigationBarColorTest () {
        wp.setNavigationBarColor({
            frontColor: '#ffffff',
            backgroundColor: '#ff0000',
            animation: {
                duration: 400,
                timingFunc: 'easeIn'
            }
        }).success(() => {
            testUtil('setNavigationBarColor-success test').success()
        }).fail(() => {
            testUtil('setNavigationBarColor-fail test').success()
        }).complete(() => {
            testUtil('setNavigationBarColor-complete test').success()
        })
    }

    setBackgroundTextStyleTest () {
        wp.setBackgroundTextStyle({
            textStyle: 'dark' // 下拉背景字体、loading 图的样式为dark
        }).success(() => {
            testUtil('setBackgroundTextStyle-success test').success()
        }).fail(() => {
            testUtil('setBackgroundTextStyle-fail test').success()
        }).complete(() => {
            testUtil('setBackgroundTextStyle-complete test').success()
        })
    }

    setBackgroundColorTest () {
        wp.setBackgroundColor({
            backgroundColor: '#ffffff', // 窗口的背景色为白色
            backgroundColorTop: '#ffffff', // 顶部窗口的背景色为白色
            backgroundColorBottom: '#ffffff', // 底部窗口的背景色为白色
        }).success(() => {
            testUtil('setBackgroundColor-success test').success()
        }).fail(() => {
            testUtil('setBackgroundColor-fail test').success()
        }).complete(() => {
            testUtil('setBackgroundColor-complete test').success()
        })
    }
}

export default function () {
    let test = new Test()
    // test.setNavigationBarTitleTest()
    // test.setNavigationBarColorTest()
    // test.setBackgroundTextStyleTest()
    // test.setBackgroundColorTest()
    // test.canIUseTest()
    // test.getSystemInfoSyncTest()
    // test.getSystemInfoTest()
    // test.getLaunchOptionsSyncTest()
    // test.switchTabTest()
    // test.reLaunchTest()
    // test.redirectToTest()
    // test.navigateToTest()
    // test.navigateBackTest()
    // test.showToastTest()
    // test.showModalTest()
    // test.showLoadingTest()
    // test.showActionSheetTest()
    // test.hideToastTest()
    // test.hideLoadingTest()
    // test.showNavigationBarLoadingTest()
}